# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details

  def require_login
    if(session[:user]!=nil)
      redirect_to :controller => 'clientes', :action => 'show', :id => session[:id]
    end
  end

  def check_login
    if(session[:user]==nil)
      redirect_to :controller => 'clientes', :action => 'index'
    end
  end

  def check_index_logeado
     @root = Cliente.find(:first, :conditions => ["id = ?", session[:id]])
     if(@root.root !="si")
      flash[:error] = 'No pudes acceder a clientes por falta de privilegios'
      redirect_to :controller => 'clientes', :action => 'show', :id => session[:id]
    end
  end

  def check_participante_root
     @root = Cliente.find(:first, :conditions => ["id = ?", session[:id]])
     if(@root.root != "si")
      flash[:error] = 'No pudes acceder a participantes por falta de privilegios'
      redirect_to :controller => 'clientes', :action => 'show', :id => session[:id]
    end
  end

    def check_categorias_root
      @root = Cliente.find(:first, :conditions => ["id = ?", session[:id]])
      if(@root.root != "si")
      flash[:error] = 'No pudes acceder a categorias por falta de privilegios'
      redirect_to :controller => 'clientes', :action => 'show', :id => session[:id]
    end
  end

  def administrador_eventos_logeado
    if (session[:user]!=nil)
#      redirect_to :controller => 'eventos', :action => 'eventos_logeado'
redirect_to '/eventos_logeado'
    end
  end

  def administrador_eventos_deslogeado
    if (session[:user]==nil)
      redirect_to :controller => 'eventos', :action => 'index'
    end
  end

  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
end
